<template>
	<view>
		<nav-custom></nav-custom>
		<u-empty v-if="isEmpty" icon="https://cdn.uviewui.com/uview/empty/data.png"></u-empty>
		<view v-else class="cont flex bg-fff justify-between flex-wrap">
			<good-item v-for="(item,index) in glist" :gdata="item"></good-item>
		</view>
		<good-spec></good-spec>
		<tab-custom></tab-custom>
	</view>
</template>

<script>
	import {ID,KEY,BASE_URL} from '../../config/index.js'
	import {$http} from '../../utils/request.js'
	import {getGoodsList} from '../../api/goods.js'
	export default {
		data() {
			return {
				glist:[],
				page:1,
				isEmpty:false  //控制数据为空结构
			};
		},
		onLoad() {
			getGoodsList().then(res=>{
				this.glist = res.results
				if(!this.glist.length){this.isEmpty=true}
				this.page++
			})
		},
		onReachBottom() { //触底分页
			console.log('触底了');
			getGoodsList(this.page).then(res=>{
				let {results} = res
				if(results.length){
					this.glist = [
						...this.glist, //原数据
						...results //新数据
					]
					this.page++
					return
				}
				uni.showToast({
					title:'这回真没了',
					icon:'none'
				})
			})
		},
		onPullDownRefresh() { //下拉刷新
			this.glist = []
			this.page = 1
			getGoodsList().then(res=>{
				uni.stopPullDownRefresh()
				this.glist = res.results
				this.page++
			})
		},
		methods: {
			handleDetail(idx) {
				uni.navigateTo({
					url:'../detail/detail?idx='+idx
				})
			}
		},
	}
</script>

<style lang="scss">
.cont{
	padding: 15upx;
}
</style>
